CREATE PROCEDURE [HaOnAzure].[RemoveEndpointFromHA]
	@dbName SYSNAME,
	@endpointName NVARCHAR(260)
AS
DECLARE @AccountName NVARCHAR(255);
DECLARE @SharedKey NVARCHAR(4000);

DECLARE @PartitionKey NVARCHAR(260);
DECLARE @RowKey NVARCHAR(260);


SELECT TOP 1 @AccountName = AccountName, @SharedKey = SharedKey 
FROM [HAOnAzure].[Credential] 
WHERE IsMaster = 1;

IF @AccountName IS NULL OR @SharedKey IS NULL
	THROW 53000, 'Default credential not found. Add it and try again.', 1;

EXEC [SQL2AzureCLR].[Azure].[DeleteEntity]
	@AccountName, @SharedKey, 1,
	'HaOnAzureEndpoint', 
	@dbName, @endpointName;
GO